module CanCamel::Validators
  module PathValidators
    include ValidatorsHelper

    def path(path:, action: nil, subject: nil, group: nil)
      raise ValidationError unless action || subject || group
      unless path && path.length == 3
        raise ValidationError, 'trying to validate not a group node or invalid node structure'
      end

      validate_element(element: path[0], value: group) if group
      validate_element(element: path[1], value: action) if action
      validate_element(element: path[2], value: subject) if subject
    end

    alias_method :action, :path
    alias_method :subject, :path
    alias_method :group, :path
  end
end
